package com.apchernykh.rozhlasapp.ui.stations;

import com.apchernykh.rozhlasapp.ui.IViewsExpirationListener;
import com.apchernykh.rozhlasapp.ui.NullViewsExpirationListener;
import com.apchernykh.rozhlasapp.ui.RozhlasAppBaseFragmentActivity;

import android.content.res.Configuration;
import android.os.Bundle;

public class StationDetailsActivity extends RozhlasAppBaseFragmentActivity implements  IViewsExpirationListener{
    @Override
    protected void onCreate(Bundle iSavedInstanceState) {
        super.onCreate(iSavedInstanceState);

        if (getResources().getConfiguration().orientation
                == Configuration.ORIENTATION_LANDSCAPE) {
            // If the screen is now in landscape mode, we can show the
            // dialog in-line with the list so we don't need this activity.
            finish();
            return;
        }

        if (iSavedInstanceState == null) {
            // During initial setup, plug in the details fragment.
        	ScheduleDetailsFragment aDetails = new ScheduleDetailsFragment();
            aDetails.setArguments(getIntent().getExtras());
            getSupportFragmentManager().beginTransaction().add(
            		android.R.id.content, aDetails).commit();
        }
    }

	@Override
	public void onResume() {
		super.onResume();
		RozhlasAppBaseFragmentActivity.mApplicationModel.mOnViewsExpiredListener = this;
	}

	@Override
	public void onPause() {
		super.onPause();
		RozhlasAppBaseFragmentActivity.mApplicationModel.mOnViewsExpiredListener  = new NullViewsExpirationListener();
	}
	

    
	@Override
	public void onViewExpired() {
		runOnUiThread(new Runnable() {
			@Override
			public void run() {
					ScheduleDetailsFragment.refresh(getSupportFragmentManager().findFragmentById(android.R.id.content));
			}
		});

		
	}
    
}
